<?php
// Menu des administrateurs/utilisateurs

if (isValidConstant() != 1) {
    fermeSessionUtilisateur();
}

$modeAdmin= ($_SESSION['gestion_site']>="Oui"?"Oui":"Non");
if ($modeAdmin!=="Oui") {
    exit;
}

$datedebut = getPeriodeCourante("début");
$datefin = getPeriodeCourante("fin");
$periode_en_cours = $datedebut . " au " . $datefin;

$jeton = filter_input(INPUT_POST, 'jeton');
if (empty($jeton)) {
    $jeton = filter_input(INPUT_GET, 'jeton');
}

function creer_menu_item_admin($modeAdmin, $etiquette, $menuName, $jeton, $icone) {
    if ($modeAdmin === "Oui") {
        $alignement = "center";
        print "<td style='vertical-align: top;' style='min-width:315px; max-width:315px;'>\n";
        print "<div style='text-align: $alignement;'>\n";
        print "<button class='styled bouton_menu' onclick='versMenu(\"$menuName\", \"$jeton\");' tabindex='$menuName' type='button'>\n";
        print "<div align='center'><i class='fa $icone'><span  class='espace_icone_menu'>$etiquette</span></i></div>\n";
        print "</button>\n";
        print "</div>\n";
        print "</td>\n";
    } else {
        print "<td style='width:300px;'></td>";
    }
}
?>
<table style='border:0px; text-align:center; margin:auto; width:auto;' cellpadding='0' cellspacing='0'>
    <tbody>
        <tr>
            <td>
                <form action='' name='horloge' enctype='text/plain'>
                    <table style='width:900px; margin:0; padding:0; height:850px;' cellpadding='0' cellspacing='0'>
                        <thead>
                            <tr>
                                <td class="img_center" colspan='3'>
                                    <img id="logoweb" src="images/logoweb.png" alt="<?php print $APPLICATION; ?>">
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <!-- Ligne vide pour espacement vertical -->
                                <td style='vertical-align: top;' colspan='2'>&nbsp;</td>
                            </tr>
                            <tr>
                                <td style='vertical-align: top;' colspan='2'>
                                    <div style='width:360px; height:163px; margin:auto; padding:0;'>
                                        <?php
                                        print "<img alt='SYNDICAT' src='logo/" . $_SESSION["syndicat"] . "." . $_SESSION['logo'] . "' width='360px;' height='163px;'>\n";
                                        print "</div>\n";
                                        ?>
                                </td>
                            </tr>

                            <?php
                            print "<tr>\n";
                            //Configuration du syndicat
                            creer_menu_item_admin($modeAdmin, "Paramètres de la centrale syndicale", "parametres_centrale", $jeton, "fa-wpforms");
                            
                            //Réactivation de compte bloqués
                            //creer_menu_item_admin($modeAdmin, "Réactivation de tous les comptes actifs bloqués", "compte_bloques", $jeton, "fa-unlock-alt");
                            
                            //Copie de sauvegarde
                            creer_menu_item_admin($modeAdmin, "Copie de sauvegarde", "copie_sauvegarde", $jeton, "fa-life-saver");
                            print "</tr>\n";
//                            print "<tr>\n";
//                            
//                            //Billet de service
//                            //creer_menu_item_admin($modeAdmin, "Ouvrir un billet de service", "billet_service", $jeton, "fa-wpforms");
//                            print "</tr>\n";

                            //Sortie
                            print "<tr>\n";
                            print "<td style='vertical-align: top;' colspan='3'>\n";
                            print "   <form name='horloge' action='index2.php' method='POST'>\n";
                            print "      <input class='styled' type=\"submit\" style='cursor:pointer;' value=\"Fermer\">\n";
                            print "      <input type='hidden' name='jeton' value='" . $_SESSION['jeton'] . "'>\n";
                            print "   </form>";
                            print "</td>\n";
                            print "</tr>\n";
                            ?>

                            <tr> 
                                <td colspan='3'> 
                                    <table style='text-align:center; margin:auto; padding-top:30px;'> 
                                        <tr> 
                                            <td style="vertical-align: top;"> 
                                                <div style="text-align:left;">Période en cours : </div> 
                                            </td> 
                                            <td style="vertical-align: top;" colspan="2"> 
                                                <div style="text-align:left;"> 
                                                    <input style="direction: ltr; background-color: rgb(204, 204, 204);" size="30" readonly="readonly" name="info2" value="<?= $periode_en_cours; ?>">
                                                </div> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td style='vertical-align: top;'> 
                                                <div style='text-align:left;'>Utilisateur branché : </div> 
                                            </td> 
                                            <td style='vertical-align: top;'> 
                                                <div style='text-align:left;'> 
                                                    <input style='background-color: rgb(204, 204, 204);' size='30' readonly='readonly' name='info3' value='<?= htmlspecialchars($_SESSION['utilisateur'], ENT_SUBSTITUTE, "UTF-8"); ?>'> 
                                                </div> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td style='vertical-align: top;'> 
                                                <div style='text-align:left;'>Prénom et nom : </div> 
                                            </td> 
                                            <td style='vertical-align: top;'> 
                                                <div style='text-align:left;'> 
                                                    <input style='background-color: rgb(204, 204, 204);' size='30' readonly='readonly' name='info4' value='<?= htmlentities($_SESSION['nomreel'], ENT_SUBSTITUTE, "UTF-8"); ?>'> 
                                                </div> 
                                            </td> 
                                        </tr> 
                                        <tr> 
                                            <td style='vertical-align: top;'> 
                                                <div align='left'>Temps restant :</div> 
                                            </td> 
                                            <td style='vertical-align: top;'> 
                                                <div align='left'> 
                                                    <input readonly='readonly' style='background-color: rgb(204, 204, 204);' name='clock' value='' size='3' dir='rtl' type='text'> 
                                                    min:sec avant la fermeture automatique de la session. 
                                                </div> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </td> 
                                <td style='vertical-align: middle;'> 
                                </td> 
                            </tr> 
                        </tbody> 
                    </table> 
                </form> 
            </td> 
        </tr> 
    </tbody> 
</table>
<script type='text/javascript' language='JavaScript'>
    function versMenu(lien, jeton) {
        if (lien === "fermer") {
            lien = "fermer.php";
        } else {
            lien = 'index2.php?page=' + lien + "&jeton=" + jeton;
        }
        window.location = lien;
    }
</script>
